package com.greensuisse.log;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;

public class ViewLog {
	public static void main(String... args) throws IOException {
		final SSHClient ssh = new SSHClient();
		// ssh.loadKnownHosts(new File(
		// "D:\\softwares\\cygwin\\home\\hly\\.ssh\\known_hosts"));
		ssh.addHostKeyVerifier("11:96:6f:35:c6:b6:72:51:ec:a5:55:d7:fe:98:eb:ef");
		ssh.connect("192.168.0.102");
		try {
			ssh.authPassword("hly", "swiss");
			final Session session = ssh.startSession();
			try {
				final Command cmd = session
						.exec("tail -100f ~/examples.desktop");

				InputStream inputStream = cmd.getInputStream();
				BufferedReader reader = new BufferedReader(
						new InputStreamReader(inputStream));
				while (true) {
					String line = reader.readLine();
					System.out.println(">>>" + line);

				}
				// cmd.join(5, TimeUnit.SECONDS);
				// System.out.println("\n** exit status: " +
				// cmd.getExitStatus());
			} finally {
				session.close();
			}
		} finally {
			ssh.disconnect();
		}
	}
}
